package com.ship.contract.bean;

import cn.hutool.core.date.DatePattern;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ship.common.core.base.ContractBaseBean;
import com.ship.common.core.base.Joinable;
import com.ship.common.core.mapping.Label;
import com.ship.common.core.mapping.SearchItem;
import com.ship.common.core.mapping.TableColumn;
import com.ship.common.core.validate.Add;
import com.ship.common.core.validate.Update;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;


import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;

/**
 * @author 31463
 */
    @TableName("con_lawyer")
@Data
public class ConLawyer extends ContractBaseBean implements Joinable {

    private static final long serialVersionUID = 8444817246697564774L;
    /**
     *合同名称
     */
    @Label(value="合同名称")
    @SearchItem
    @TableColumn
    private String contractName;

    /**
     *执行编号
     */
    @Label(value="执行编号")
    @SearchItem
    @TableColumn
    private String contractNumber;

    /**
     *甲方
     */
    @Label(value="甲方")
    @TableColumn
    @NotBlank(message = "甲方不能为空", groups = {Update.class, Add.class})
    @Size(max = 255, message = "甲方长度不能超过255", groups = {Update.class, Add.class})
    private String partyA;

    /**
     *乙方
     */
    @Label(value="乙方")
    @SearchItem
    @TableColumn
    @NotBlank(message = "乙方不能为空", groups = {Update.class, Add.class})
    @Size(max = 255, message = "乙方长度不能超过255", groups = {Update.class, Add.class})
    private String partyB;

    /**
     *签订日期
     */
    @Label(value="签订日期")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    @SearchItem
//    @TableColumn
    @NotNull(message = "签订日期不能为空", groups = {Update.class, Add.class})
    private Date signingDate;

    @TableColumn
    @TableField(exist = false)
    @Label(value="签订日期")
    private String signingDateStr;

    /**
     *删除申请
     */
    @Label(value="删除申请")
    private Integer delApply;

    /**
     *合同状态
     */
    @Label(value="合同状态",enumContent = "合同状态")
    private Integer status;

    /**
     *是否是优秀案例
     */
    @Label(value="是否是优秀案例",enumContent = "是否是优秀案例")
    private Integer excellent;

    /**
     * 合同上传时间
     */
    @Label(value="合同上传时间")
//    @TableColumn
    @TableField(fill = FieldFill.INSERT)
    private Date createDate;

    @TableColumn
    @Label(value="合同上传时间")
    @TableField(exist = false)
    private String createDateStr;

    /**
     *到期时间
     */
    @Label(value="到期时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
//    @TableColumn
    private Date expirationDate;

    @Label(value="到期时间")
    @TableColumn
    @TableField(exist = false)
    private String expirationDateStr;

    @ApiModelProperty(value = "生效日期")
    @Label(value="合同生效日期")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
//    @TableColumn
    private Date comeIntoForceDate;

    @Label(value="合同生效日期")
    @TableColumn
    @TableField(exist = false)
    private String comeIntoForceDateStr;

    @ApiModelProperty(value = "有效期/年")
    @Label(value="有效期")
    @TableColumn
    private Integer effectiveDate;

    /**
     * 创建者
     */
    @Label(value="创建者")
    @TableColumn
    @TableField(fill = FieldFill.INSERT)
    private String createBy;

    @ApiModelProperty(value = "律师合同支付文本")
    @Label(value="律师合同支付文本")
    private String payDaysText;

    @ApiModelProperty(value = "支付时间")
    @Label(value="支付时间")
//    @TableColumn
    private Integer payTime;

    @ApiModelProperty(value = "支付时间（天）类型，工作日/自然日")
    @Label(value="支付时间（天）类型",enumContent = "支付时间（天）类型")
    private Integer payDaysType;

    /**
     * 附件地址
     */
    @TableField(exist = false)
    private String filePath;

    @Label(value="删除流程实例id")
    private String deleteProcessInstanceId;

    @Label(value="支付时间")
    @TableField(exist = false)
    @TableColumn
    private String payDaysStr;

    public String getPayDaysStr() {
        String result = null;
        if (getPayTime() != null) {
            if(null != getPayDaysType()){
                if (getPayDaysType() == 1) {
                    if (StringUtils.isNotBlank(getPayDaysText())) {
                        result = getPayDaysText() + getPayTime() + "工作日";
                    } else {
                        result = getPayTime() + "工作日";
                    }
                } else if (getPayDaysType() == 2) {
                    if (StringUtils.isNotBlank(getPayDaysText())) {
                        result = getPayDaysText() + getPayTime() + "自然日";
                    }else{
                        result = getPayTime() + "自然日";
                    }
                }
            }
        }
        return result;
    }

    public String getSigningDateStr() {
        String SigningDateStr = null;
        if (null != this.getSigningDate()){
            SigningDateStr = cn.hutool.core.date.DateUtil.format(this.getSigningDate(), DatePattern.NORM_DATE_FORMATTER);
        }
        return SigningDateStr;
    }

    public String getCreateDateStr() {
        String createDateStr = null;
        if (null != this.getCreateDate()){
            createDateStr = cn.hutool.core.date.DateUtil.format(this.getCreateDate(), DatePattern.NORM_DATETIME_FORMATTER);
        }
        return createDateStr;
    }


    public String getExpirationDateStr() {
        String expirationDateStr = null;
        if (null != this.getExpirationDate()){
            expirationDateStr = cn.hutool.core.date.DateUtil.format(this.getExpirationDate(), DatePattern.NORM_DATETIME_FORMATTER);
        }
        return expirationDateStr;
    }

    public String getComeIntoForceDateStr() {
        String comeIntoForceDateStr = null;
        if (null != this.getComeIntoForceDate()){
            comeIntoForceDateStr = cn.hutool.core.date.DateUtil.format(this.getComeIntoForceDate(), DatePattern.NORM_DATETIME_FORMATTER);
        }
        return comeIntoForceDateStr;
    }

    @Override
    public String getLabel() {
        return null;
    }

    @Override
    public String getValue() {
        return null;
    }
}
